package com.bw.hongye.user.controller;

import com.aliyun.common.utils.PageUtils;
import com.aliyun.common.utils.R;
import com.bw.hongye.user.entity.UserEntity;
import com.bw.hongye.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;




/**
 * 
 *
 * @author tZhe
 * @email tZhe@hongye.com
 * @date 2021-07-16 21:12:28
 */
@RestController
@CrossOrigin
@RequestMapping("user/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = userService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{userId}")
    public R info(@PathVariable("userId") Long userId){
		UserEntity user = userService.getById(userId);

        return R.ok().put("user", user);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody UserEntity user){
		userService.save(user);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody UserEntity user){
		userService.updateById(user);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] userIds){
		userService.removeByIds(Arrays.asList(userIds));

        return R.ok();
    }

    @RequestMapping("/userLogin")
    public UserEntity userLogin(@RequestBody UserEntity user){
        String userName = user.getUserName();
        System.out.println(userName+"12333333333333333333333");
        return userService.userLogin(user);
    }



}
